package com.sline.stream;

import java.io.*;

public class Demo4_BufferedStream {
    public static void main(String[] args) throws IOException {
        // demo1();

        /*
        * close方法具有刷新的功能
        *   在关闭流之前, 就会先刷新一次缓冲区, 将缓冲区的字节全部刷新到文件上, 再关闭流
        * flush方法
        *   具备刷新缓冲区的功能, 刷新完成后还可以继续写, close方法执行后就不能再写了*/
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("abc.mp4"));
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("copy.mp4"));

        int b;
        while ((b = bis.read()) != -1) {
            bos.write(b);
        }

        bos.flush();
        bis.close();
        bos.close();
    }

    private static void demo1() throws IOException {
        FileInputStream fis = new FileInputStream("abc.mp4");
        FileOutputStream fos = new FileOutputStream("copy.mp4");
        BufferedInputStream bis = new BufferedInputStream(fis);
        BufferedOutputStream bos = new BufferedOutputStream(fos);

        int b;
        while ((b = bis.read()) != -1) {
            bos.write(b);
        }

        bis.close();
        bos.close();
    }
}
